import KoaRouter from 'koa-router'
import { Models } from '../../../../common/typings/modle'

import { command } from '../../../../server/mysql'
import { ParameterException, Success } from '../../../../core/HttpException'
import { format } from '../../../../common/utils/date'
import Config from '../../../../config/Config'

import validator from '../../../../middlewares/validator'
import schema from '../../../../common/apiJsonSchema/system/auth/register'
import verificationCodeValidator from '../../../../middlewares/verificationCodeValidator'

const router = new KoaRouter({
  prefix: `${Config.API_PREFIX}v1/system/auth`,
})

router.post('/register', validator(schema, 'body'),verificationCodeValidator, async (ctx: Models.Ctx) => {
  const { password, username, email, smsCode } = ctx.request.body as any
  const date = format(new Date())
  await command(`
  INSERT INTO system_user ( user_name, email, password, created_at, updated_at)
  VALUES
  ( '${username}', '${email}', '${password}', '${date}', '${date}' );`)
  // ctx.response.body = {
  //   ...new Success()
  // }
  throw new Success()
})
export default router
